package com.sh.线程的创建方式;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 线程池创建 {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        // 提交 10 个任务
        for (int i = 0; i < 10; i++) {
            final int threadId = i; // lambda 中使用需要是 final 或 effectively final
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程 " + threadId + " 执行");
                }
            });
        }
        executorService.shutdown();
    }
}

